#include <autoconfig.h>
#include <stdio.h>
#include <otdr-peripheral.h>
#include <printl.h>

#define CONFIG_DS2782 1
int get_bat_vol(double *power1, double *power2);

int main(int argc, char **argv)
{

    int ret = 0;
_Again:

    setBacklightTime(13);
#if 1
    int apd_temp = 0;
    ret          = getTemperature(&apd_temp);
    if (ret == -1) {
	PRINTE("getTemperature()");
	return -1;
    }
    printf("APD temp(℃ ) %0.2f\n", (float)apd_temp / 1000);
#endif

    int bat1 = 0, bat2 = 0, adapter = 0;
    ret = getChargeState(&bat1, &bat2, &adapter);
    if (ret == -1) {
	PRINTE("getChargeState()");
	return -1;
    }
    printf("ChargeState:\n");
    printf("\tbat1:%d\n", bat1);
    printf("\tbat2:%d\n", bat2);
    printf("\tadapter:%d\n", adapter);

    double vol1 = 0, vol2 = 0;
    double ad_v1 = 0, ad_v2 = 0, bat_v1 = 0, bat_v2 = 0, C = 0, K = 0;
    float  vol_temp = 0;

    ret = get_bat_vol(&vol1, &vol2);
    if (ret == -1) {
	PRINTE("get_bat_vol()");
	return -1;
    }
#if CONFIG_DS2782
    printf("Bat ADC(mV): %0.2f %0.2f\n", vol1, vol2);
#else
    printf("Bat ADC(mV): %0.2f %0.2f\n", vol1 * 1000, vol2 * 1000);
#endif
    get_temp_vol(&vol_temp);

    int power1 = 0, power2 = 0;

    ret = getBatteryPower(&power1, &power2);
    if (ret == -1) {
	PRINTE("getBatteryPower()");
	return -1;
    }
    printf("Bat(mV):ret %d     %d    %d\n", ret, power1, power2);

#if CONFIG_PPH_DEBUG
    goto _Again;
#endif
    return 0;
}
